﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RpgMVX_SavesManager
{
    public partial class SelectGameFolder : Form
    {
        private bool changed = false;
        public SelectGameFolder()
        {
            InitializeComponent();
        }

        private void viewFolder_Click(object sender, EventArgs e)
        {
            string path;
            while((path = Utils.openFolderSelect()) == "-1")
            {
                MessageBox.Show("请选择一个文件夹", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.textBox1.Text = path;
            changed = true;
        }

        private void confirm_Click(object sender, EventArgs e)
        {
            if (Utils.isValidPath(this.textBox1.Text) && Utils.isGameFolder(this.textBox1.Text))
            {
                Setting.gameFolder = this.textBox1.Text;
                GetSetSettings.savePath(textBox1.Text);
                this.Close();
                return;
            }
            MessageBox.Show("请输入一个有效的文件夹!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            viewFolder_Click(sender, e);
        }

        private void SelectGameFolder_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.DialogResult = changed ? DialogResult.OK : DialogResult.Cancel;
        }
    }
}
